<include file="Public:header" />
<!--主体内容-->
<!--左边-->
<div class="centent_box">
    <include file="Public:left" />
    <!--右边-->
    <div class="centent_right_box">
        <div class="centent_right rightCon">
            <div class="Mtitle">
                <ul>
                    <li class="on"><span>系统管理</span></li>
                </ul>
                <div class="rightWord"><a href="{:U('Set/index')}">角色设置</a> &gt;&gt; 角色分配</div>
            </div>
            <form id="info_form" action="{:U('Set/allot')}" method="post" >
            <div class="con_div">
                <ul class="formList width2 list_ul list_mp">
                    <li>
                        <label>角色名称：</label>
                        <input type="text"  name="title" value="{$role.name}" class="inputStyle width3" readonly>
                    </li>
                    <volist name="auths" id="au" key="i">
                        <li class="li_checkbox">
                            <label class="lw90">{$au.title}：</label>
                            <volist name="au.sub" id="vo" key="ii">
                                <input type="checkbox" name="auths[]" id="auth-{$i}-{$ii}" value="{$vo.id}" {$vo.checked} /><label for="auth-{$i}-{$ii}">{$vo.title}</label>
                            </volist>
                        </li>
                    </volist>
                    <li>
                        <label></label>
                        <input type="hidden" value="{$role.id}" name="roleid">
                    </li>
                    <li>
                        <label></label>
                        <input type="submit" value="提 交" class="btnStyle">
                    </li>
                </ul>
            </div>
            </form>
        </div>
    </div>
</div>
<js file="__S__/ueditor/ueditor.config.js" charset="utf-8" />
<js file="__S__/ueditor/ueditor.all.min.js" charset="utf-8" />
<js file="__S__/ueditor/lang/zh-cn/zh-cn.js" charset="utf-8" />
<js file="__JS__/uploadImg.js" charset="utf-8" />
<script type="text/javascript">
    window.UEDITOR_HOME_URL='__STATIC__/ueditor/';
    window.onload=function(){
        window.UEDITOR_CONFIG.initialFrameWidth=880;
        window.UEDITOR_CONFIG.initialFrameHeight=500;
        upmoreimg();
    }
    var ue = UE.getEditor('info', {
        toolbars: [[
            'fullscreen', 'source', '|',
            'bold', 'italic', 'underline', '|', 'fontfamily','fontsize', '|', 'imagenone', 'imageleft', 'imageright', 'imagecenter', 'simpleupload','|', 'kityformula', 'preview'
        ]]
    });
</script>
<script src="__S__/js/jquery.validate.js"></script>
<script type="text/javascript">
    $(function(){
        $("#info_form").validate({
            rules: {
                "data[title]": {
                    required: true,
                    minlength: 2
                },
                "data[area_id]": {
                    area:true
                },
                "data[area]": {
                    required: true,
                    minlength: 2
                },
                "data[floor]": {
                    required: true
                },
                "data[total_price]": {
                    required: true
                },
                "used_type[]": {
                    required: true,
                    minlength: 2
                },
                "data[years]": {
                    required: true,
                    minlength: 4
                },
                "data[address]": {
                    required: true,
                    minlength: 5
                },
                "data[map]": {
                    required: true,
                    minlength: 10
                },
                "data[contacts]":{
                    required: true
                },
                "data[phone]":{
                    required: true
                }

            },
            messages: {
                "data[title]": {
                    required: "请输入房源名称",
                    minlength: "房源名称一定要两个字以上"
                },
                "data[area]": {
                    required: "请输入房源面积",
                    minlength: "房源面积一定要两个字以上"
                },
                "data[floor]": {
                    required: "请填写所在楼层"
                },
                "data[total_price]": {
                    required: "请填写房源总价"
                },
                "used_type[]": {
                    required: "楼盘类型一定要选择",
                    minlength: "楼盘类型选择两种以上"
                },
                "data[years]": {
                    required: "请填写房源年份",
                    minlength: "请输入正确的房源年份"
                },
                "data[address]": {
                    required: "请填写房源所在地址",
                    minlength: "房源所在地址请写详细点"
                },
                "data[map]": {
                    required: "输入房源百度地图坐标",
                    minlength: "请输入正确的房源地图坐标"
                },
                "data[contacts]": {
                    required: "输入出售联系人"
                },
                "data[phone]": {
                    required: "请输入联系电话"
                }
            }
        });

        //所属地区
        $.validator.addMethod("area", function(value, element) {
           if($("#area_id").val()!=0){
               return true
           }else{
               return false
           }
        }, "请选择所属地区");
    });

    $("#area_id").change(function(){
        var v = $(this).val();
        if(v!=0){
            $.ajax({
                type: "post",
                url : "{:U('Ajax/getEstate')}",
                dataType:'json',
                data:{area_id:v},
                success: function(json){
                    var html = " <option value='0'>--请选择小区--</option>";
                    if(json.status==1){
                     var data = json.data;
                    $.each(data,function (k,v){
                       html +=  " <option value='"+v.id+"'>"+ v.title+"</option>";
                     });
                    }else{
                       alert('找不到对应的小区信息');
                    }
                    $("#estate_id").empty();
                    $("#estate_id").append(html);
                }
            });
        }
    });
    $('#estate_id').change (function (){
        var eid = $(this).val();
        if(eid!=0){
            $.ajax({
                type: "post",
                url : "{:U('Ajax/getDict')}",
                dataType:'json',
                data:{eid:eid},
                success: function(json){
                    var html = " <option value='0'>--请选择字典--</option>";
                    if(json.status==1){
                        var data = json.data;
                        $.each(data,function (k,v){
                            html +=  " <option value='"+v.id+"'>"+ v.build +'栋'+ v.fool +'层'+ v.room+"房</option>";
                        });
                    }else{
                        alert('找不到对应字典信息');
                    }
                    $("#dict_id").empty();
                    $("#dict_id").append(html);
                }
            });
        }
    });
    //匹配房源字典
    $("#title").blur(function(){
        var title = $(this).val ();
        var url = "{:U ('Used/ajaxMach')}";
        var data = {title:title};
        $.get (url, data, function (response){
            if (response.state == 'ok'){
                var html = '<div class="ajax-msg">';
                $.each (response.data, function(i,v){
                    html += '<div class="ajax-buttom" onclick="fill('+v.id+')"><button class="button" value="'+v.id+'">'+v.title+'</button></div>';
                });
                html += '</div>';
                layer.open({
                    area: ['300px', '300px'],
                    type: 1,
                    content: html
                });
            }else{
                layer.open({
                    type: 1,
                    content: '<div><div class="ajax-buttom"><button class="button">没有相关的房源字典</button></div></div>'
                });
            }
        }, 'json');
    });
    function fill (eid){
        layer.closeAll();
        var url = "{:U ('used/ajaxDict')}";
        var data = {eid:eid};
        $.get (url, data, function (resp){
            console.log(resp.state);
            if (resp.state == 'ok'){
                var data = resp.data;
                var title = data.cname+data.ename;
                $('#title').val(title);
                $('#estate_name').val(data.ename);
                $('#estate_id').val(data.eid);
                $('#area').val(data.cname);
                $('#area_id').val(data.cid);
                $('#map').val(data.map);
                $('#years').val(data.years);
                $('#addr').val(data.address);
                for_sele ('build', data.build);
                for_sele ('floor', data.floor);
                for_sele ('room', data.room);
            }
        },'json');
    }
    function for_sele (id,conut){
        var html = '';
        var unit = '栋';
        if (id == 'floor') unit = '层';
        if (id == 'room') unit = '房';
        for (var i=1;i<=conut;i++){
            html += '<option value="'+i+'">'+i+unit+'</option>';
        }
        $('#'+id+" option:eq(0)").nextAll('option').remove();
        $("#"+id).append(html);
    }
    $('#room').click(function (){
        var build = $('#build').val();
        var floor = $('#floor').val();console.log(build==0);
        if (build==0 || floor==0){
            alert('请选择楼栋&楼层')
            return false;
        }

        var room = $(this).val();
        var eid = $('#estate_id').val();
        var url = "{:U('used/getDict')}",data = {build:build,floor:floor,room:room,eid:eid};
        $.get(url, data, function (resp){
            if (resp.state == 'ok'){
                $('#dict_id').val(resp.data.id);
                $('#proportion').val(resp.data.area);
                $('#house_type').val(resp.data.house_type);
            }
        },'json');
    })
    $('#total').blur(function(){
        var total = $(this).val();
        var area = $('#proportion').val();
        var average = parseFloat(total)/parseFloat(area);
        $('#average').val(average.toFixed(2));
    })


</script>
<include file="Public:footer" />